//
//  YHStatusRetweetView.swift
//  YHWeibo
//
//  Created by yuhao.mac on 16/6/29.
//  Copyright © 2016年 yuhao.mac. All rights reserved.
//

import UIKit
import SnapKit

class YHStatusRetweetView: UIView {
    
    var retweetViewBottomConstraint:Constraint?
    
    var status:YUStatus?{
        didSet{
            contentLabel.text = status?.retweeted_status?.text
            
            //卸载约束
            retweetViewBottomConstraint?.uninstall()
            
            if status?.retweeted_status?.pic_urls?.count > 0 {
                //有配图
                //显示配图
                pictureView.hidden = false
                //赋值
                pictureView.pic_urls = status?.retweeted_status?.pic_urls
                //更新约束
                self.snp_makeConstraints { (make) -> Void in
                    retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(StautsMargin).constraint
                }
            }else{
                //没有图
                pictureView.hidden = true
                
                self.snp_makeConstraints { (make) -> Void in
                    retweetViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(StautsMargin).constraint
                }
            }
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    private func setupUI(){
        backgroundColor =  RGB(237,green: 237,blue: 237)
        addSubview(contentLabel)
        addSubview(pictureView)
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self).offset(StautsMargin)
            make.top.equalTo(self).offset(StautsMargin)
        }
        
        //配图
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(StautsMargin)
            make.left.equalTo(contentLabel)
        }
        
        self.snp_makeConstraints { (make) -> Void in
            retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(StautsMargin).constraint
        }
        
        //text
//        contentLabel.text = "StautsMarginStautsMarginStautsMarginStautsMarginStautsMarginStautsMarginStautsMarginStautsMarginStautsMarginStautsMarginStautsMarginStautsMarginStautsMarginStautsMarginStautsMargin"
        
    }
    
    private lazy var contentLabel:UILabel = UILabel(textColor: UIColor.darkGrayColor(), textFont: 15, maxWidth: SCREENW - 2*StautsMargin)
    
    //配图
    private lazy var pictureView:YHPictureView = YHPictureView()
}







